#include <iostream>

// 抽象策略类
class Strategy
{
public:
    virtual void execute() = 0;
};

// 具体策略类A
class StrategyA : public Strategy
{
public:
    void execute() override
    {
        std::cout << "StrategyA::execute()" << std::endl;
    }
};

// 具体策略类B
class StrategyB : public Strategy
{
public:
    void execute() override
    {
        std::cout << "StrategyB::execute()" << std::endl;
    }
};

class Context
{
public:
    Context(Strategy *stra)
        : strategy(stra)
    {
    }

    void setContext(Strategy *stra)
    {
        strategy = stra;
    }

    void executeStrategy()
    {
        strategy->execute();
    }

private:
    Strategy *strategy;
};

int main()
{
    StrategyA strategyA;
    StrategyB strategyB;

    Context context(&strategyA);
    context.executeStrategy();

    context.setContext(&strategyB);
    context.executeStrategy();

    return 0;
}

